import requests
import json
# 替换为你的钉钉机器人Webhook URL
webhook_url = "https://oapi.dingtalk.com/robot/send?access_token=9e920cf36336713b4e506123f6f8c6ea9ce3f49ef20395e6bfb753b752d22f11"
    
# 要@的手机号列表
at_mobiles = [""]

# 是否@所有人
is_at_all = False

def send_dingtalk_message(webhook_url, message, at_mobiles=None, is_at_all=False):
    headers = {
        'Content-Type': 'application/json'
    }
    
    data = {
        "msgtype": "text",
        "text": {
            "content": message
        },
        "at": {
            "atMobiles": at_mobiles if at_mobiles else [],
            "isAtAll": is_at_all
        }
    }
    
    response = requests.post(webhook_url, headers=headers, data=json.dumps(data))
    return response.json()

if __name__ == "__main__":
    # 要发送的消息内容
    message = "通知：Hello, this is a test message from DingTalk robot."
    
    result = send_dingtalk_message(webhook_url, message, at_mobiles, is_at_all)
    print(result)